]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
mpris: Validate received data against the expected types from the spec
authorPhilip Chimento <philip@endlessm.com>
Tue, 29 Oct 2019 00:06:40 +0000 (17:06 -0700)
committerFlorian Müllner <florian.muellner@gmail.com>
Tue, 29 Oct 2019 19:25:16 +0000 (19:25 +0000)
In the wild we have buggy clients (notably Chromium 77 and earlier) that
send metadata with the wrong types. Previously, this would throw an
exception and prevent the MPRIS information from showing up in the
message list.

This changes the code to check if any incoming metadata is of the type
it is expected to be, and logs a warning if not, then continues on with
a default value.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1362

js/ui/mpris.js

index c46f9f01c5d648f8533804bb9491b511af36e50f..240e99e5f299042506e37246536a41e4f4adcf94 100644 (file)
@@ -95,6 +95,7 @@ var MprisPlayer = class MprisPlayer {
         this._trackArtists = [];
         this._trackTitle = '';
         this._trackCoverUrl = '';
+        this._busName = busName;
     }
 
     get status() {
@@ -177,9 +178,36 @@ var MprisPlayer = class MprisPlayer {
         for (let prop in this._playerProxy.Metadata)
             metadata[prop] = this._playerProxy.Metadata[prop].deep_unpack();
 
-        this._trackArtists = metadata['xesam:artist'] || [_("Unknown artist")];
-        this._trackTitle = metadata['xesam:title'] || _("Unknown title");
-        this._trackCoverUrl = metadata['mpris:artUrl'] || '';
+        // Validate according to the spec; some clients send buggy metadata:
+        // https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata
+        this._trackArtists = metadata['xesam:artist'];
+        if (!Array.isArray(this._trackArtists) ||
+            !this._trackArtists.every(artist => typeof artist === 'string')) {
+            if (typeof this._trackArtists !== 'undefined')
+                log(`Received faulty track artist metadata from ${
+                    this._busName}; expected an array of strings, got ${
+                    this._trackArtists} (${typeof this._trackArtists})`);
+            this._trackArtists =  [_("Unknown artist")];
+        }
+
+        this._trackTitle = metadata['xesam:title'];
+        if (typeof this._trackTitle !== 'string') {
+            if (typeof this._trackTitle !== 'undefined')
+                log(`Received faulty track title metadata from ${
+                    this._busName}; expected a string, got ${
+                    this._trackTitle} (${typeof this._trackTitle})`);
+            this._trackTitle = _("Unknown title");
+        }
+
+        this._trackCoverUrl = metadata['mpris:artUrl'];
+        if (typeof this._trackCoverUrl !== 'string') {
+            if (typeof this._trackCoverUrl !== 'undefined')
+                log(`Received faulty track cover art metadata from ${
+                    this._busName}; expected a string, got ${
+                    this._trackCoverUrl} (${typeof this._trackCoverUrl})`);
+            this._trackCoverUrl = '';
+        }
+
         this.emit('changed');
 
         let visible = this._playerProxy.CanPlay;